﻿$(window).load(function(){
    $('.boxcenter .midd .inn img').each(function(){
	    var that = $(this);
        var preloadImage = new Image();
	    preloadImage.onload = function(){
            var boxcenter = that.parent().parent();
            var maxWidth = boxcenter.width();
            var maxHeight = boxcenter.height();
            var ratio = this.width * 1.0 / this.height;
            var width = maxWidth;
            var height = maxHeight;
            if (width > this.width && height > this.height) {
                width = this.width;
                height = this.height;
            } else {
                width = Math.round(height * ratio);
                if (width > maxWidth) {
                    width = maxWidth;
                    height = Math.round(width / ratio);
                }
            }
            that.width(width);
            that.height(height);
	    };
	    preloadImage.src = this.src;
    });
});